package com.diaohaiwen.common.log;

import com.diaohaiwen.common.enums.LogTypeEnum;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;

import java.util.Arrays;

import static com.diaohaiwen.common.enums.LogTypeEnum.DEFAULT;

/**
 * 日志配置类
 *
 * @author 刁海文
 * @Remark
 * @since 2022/5/30 9:28
 */
@Data
@Component
@Configuration
@ConfigurationProperties(prefix = "config.log")
@EnableConfigurationProperties
public class LogProperties {

    /**
     * 日志实现方式
     */
    private LogTypeEnum classType = DEFAULT;

    /**
     * 是否启用
     */
    private boolean enable;
    /**
     * http 请求日志
     */
    private boolean http = true;
    /**
     * SQL日志配置
     */
    private boolean db = true;
    /**
     * logback日志配置
     */
    private boolean logback = true;
    /**
     * 服务运行日志配置
     */
    private boolean app = true;
    /**
     * MQ日志配置
     */
    private boolean mq = true;
    /**
     * 过滤的logger name 支持使用正则
     */
    private String[] excluded;

    public boolean isExcluded(String path) {
        AntPathMatcher matcher = new AntPathMatcher();
        return Arrays.stream(excluded).anyMatch(exclude -> matcher.match(exclude, path));
    }


}
